package com.bigger.controller;

import com.bigger.dto.UpdateAddressDTO;
import com.bigger.entity.AddressBook;
import com.bigger.result.Result;
import com.bigger.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/address")
public class AddressController {
    @Autowired
    private AddressService addressService;
    @GetMapping("/get")
    public Result<List<AddressBook>> get(){
        List<AddressBook> addressBooks=addressService.get();
        return Result.success(addressBooks);
    }
    @PutMapping("/update")
    public Result<String> update(@RequestBody UpdateAddressDTO updateAddressDTO){
        addressService.update(updateAddressDTO);
        return Result.success("修改成功");
    }
    @PostMapping("/add")
    public Result<String> add(@RequestBody UpdateAddressDTO updateAddressDTO){
        addressService.add(updateAddressDTO);
        return Result.success("添加成功");
    }
    @DeleteMapping("/delete")
    public Result<String> delete(Long id){
        addressService.delete(id);
        return Result.success("删除成功");
    }
    @GetMapping("/get/{id}")
    public Result<AddressBook> getById(@PathVariable("id") Long id){
        AddressBook addressBook=addressService.getById(id);
        return Result.success(addressBook);
    }
}
